package com.idearworld.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.idearworld.beans.QueryBean;
import com.idearworld.dao.BlogMapper;
import com.idearworld.model.Blog;
import com.idearworld.model.BlogExample;
import com.idearworld.service.BlogService;

@Service
public class BlogServiceImpl implements BlogService{

	@Autowired
	private BlogMapper blogMapper;
	
	@Override
	public Blog createBlog(Blog blog) {
		if(blog == null || blog.getBlogContent() == null 
			|| blog.getTitle() == null || blog.getTitle().equals("")){
			return null;
		}
		blogMapper.insert(blog);
		return blog;
	}

	@Override
	public List<Blog> queryBlog(QueryBean queryBean) {
		BlogExample example=new BlogExample();
		if(queryBean !=null && queryBean.getKeyWord()!=null && !queryBean.getKeyWord().equals("")){
			example.or().andTitleLike(queryBean.getKeyWord());
		}else{
			example.setOrderByClause(" create_date desc limit 0,10 ");
		}
		
		return blogMapper.selectByExample(example);
	}

	@Override
	public Blog getBlogById(Integer blogId) {
		return blogMapper.selectByPrimaryKey(blogId);
	}

	

}
